Because of a huge amount of video data, in an actual application, video data usually needs to be compressed and coded. A coder processes the video data through prediction, transform, quantization, and entropy coding processes, so as to implement data compression to generate a video stream. The video stream may be used for storage or network transmission. A decoder performs a decoding operation on the video stream through entropy decoding, inverse quantization, inverse transform, and predictive compensation, so as to reconstruct the video data.
In an H.264 coding technology, accurate control of a signal compression artifact is implemented by using a quantization matrix (quantization matrix, QM). A coder provides a group of QMs suitable for a currently-to-be-coded image according to content of the current image, and then writes code of the QMs into a code stream. After a decoder receives the code stream carrying QM information, the decoder obtains the QM information through decoding, and obtains the image through decoding by using the QM information. In H.264, each frame of image may have a maximum of eight groups of QM matrices QMi, where i=1, 2, . . . 8. The eight groups of QM matrices indicate six QMs in 4*4 transform: luminance Y, chrominance Cb, and chrominance Cr of intraframe prediction, and luminance Y, chrominance Cb, and chrominance Cr of interframe prediction, and two QMs in 8*8 transform: luminance Y of intraframe prediction and interframe prediction. Because a data amount of the QM information is large, the QM information needs to be compressed and coded, so as to reduce the number of bits used for representing the QM information. In H.264, six 4*4 quantization matrices and two 8*8 quantization matrices are separately coded by using the following compression method. Specific steps are as follows:
First step: Perform a scanning operation on a two-dimensional quantization matrix to generate one-dimensional data;
Second step: Perform DPCM coding on the one-dimensional data; and
Third step: Perform entropy coding on the coded data and write the data on which the entropy coding has been performed into a code stream.
In the foregoing solution, both transform and quantization use N*N square matrices, and when non-square transform and quantization matrices are used, for an N*M quantization matrix, many bits are required to represent the quantization matrices according to the foregoing quantization matrix compression method; and when an applied bandwidth is quite small, bits used for transmitting the quantization matrices severely affect the quality of a coded image.